package HttpServlet;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;

@WebServlet ("/*")
    public class AllServlet extends Hasmap {
        Hasmap.AllController allController=new Hasmap.AllController();
        @Override
        public void init() throws ServletException {
            HashMap<String, String> map = allController.map;
            map.put("/day0924/a","a");
            map.put("/day0924/b","b");
        }

        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //获取实际请求的uri
            String requestURI = request.getRequestURI();
            System.out.println("requestURI:"+requestURI);
            HashMap<String, String> map = allController.map;
            String methodName = map.get(requestURI);

            //通过反射调用对应方法
            Class<Hasmap.AllController> allControllerClass = Hasmap.AllController.class;
            try {
                Method declaredMethod = allControllerClass.getDeclaredMethod(methodName);
                //执行对应方法
                declaredMethod.invoke(allController);
            } catch (Exception e) {
            }
        }
    }
